package com.ley.yikang.util;

import lombok.Data;

@Data
public class ResultData<T> {

    // 结果状态码
    private int code;

    // 响应信息
    private String msg;

    // 响应数据
    private T data;

    public ResultData() {
    }

    public static <T> ResultData<T> success(T data, String msg) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.RC200.getCode());
        resultData.setMsg(msg);
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> fail(String msg) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ReturnCode.RC500.getCode());
        resultData.setMsg(msg);
        return resultData;
    }

    public static <T> ResultData<T> fail(int code, String msg) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMsg(msg);
        return resultData;
    }
}

